package com.blog1.common.util;

import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;

import java.util.UUID;

public class SecurityUtils {

    public static String encrypt(String password) {
      String salt= UUID.randomUUID().toString().replace("-","");
      String securityPassword = DigestUtils.md5DigestAsHex((salt+password).getBytes());
      return salt+securityPassword;
    }

    public static boolean verify(String inputPassword,String sqlPassword) {
if(!StringUtils.hasLength(inputPassword))return false;
if(sqlPassword==null||sqlPassword.length()!=64)return false;
String salt=sqlPassword.substring(0,32);
String securityPassword = DigestUtils.md5DigestAsHex((salt+inputPassword).getBytes());
return sqlPassword.equals(salt+securityPassword);
    }



}
